class Slider extends egret.DisplayObjectContainer{
	public constructor(w:number,end:number) {
		super();
		this.width = w;
		this.height = 20;
		this.init(end);
	}
	private huadao:egret.Shape;
	private huakuai:egret.Shape;
	private value:number;	//音量大小


	private init(end:number){
		let huacao:egret.Shape = new egret.Shape();
		huacao.graphics.lineStyle(10,0xcccccc,0.8);
		huacao.graphics.moveTo(0,5);
		huacao.graphics.lineTo(this.width,5);
		huacao.graphics.endFill();
		this.addChild(huacao);

		this.huadao = new egret.Shape();
		this.huadao.graphics.lineStyle(10,0x00ff00,0.8);
		this.huadao.graphics.moveTo(0,5);
		this.huadao.graphics.lineTo(this.width*end,5);
		this.huadao.graphics.endFill();
		this.addChild(this.huadao);

		this.huakuai = new egret.Shape();
		this.huakuai.graphics.beginFill(0xffffff,0.8);
		this.huakuai.graphics.drawCircle(this.width*end,5,10);
		this.huakuai.graphics.endFill();
		this.addChild(this.huakuai);

		this.huakuai.touchEnabled = true;
		this.touchEnabled = true;
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onbegin,this);
		this.addEventListener(egret.TouchEvent.TOUCH_END,this.onend,this);
		this.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.onoutside,this);
	}
	private onbegin(e:egret.TouchEvent){
		this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.onmove,this);
		this.changeVeiw(e.localX);
		
		
	}
	private onmove(e:egret.TouchEvent){
		this.changeVeiw(e.localX);
	}
	private onend(e:egret.TouchEvent){
		this.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.onmove,this);
		this.changeVeiw(e.localX);
	}
	private onoutside(e:egret.TouchEvent){
		this.changeVeiw(e.localX);
	}
	private changeVeiw(x:number){	
		(x<0)&&(x=0);
		(x>this.width) && (x=this.width);
		this.value = x/this.width;
		// console.log(this.value);

		this.parent.dispatchEvent(new egret.Event("gbyl",false,false,this.value))
		//改变滑块的圆心
		this.huakuai.graphics.clear();
		this.huakuai.graphics.beginFill(0xffffff,0.8);
		this.huakuai.graphics.drawCircle(x,5,10);
		this.huakuai.graphics.endFill();
		
		//改变滑道的终点
		this.huadao.graphics.clear();
		this.huadao.graphics.lineStyle(10,0x00ff00,0.8);
		this.huadao.graphics.moveTo(0,5);
		this.huadao.graphics.lineTo(x,5);
		this.huadao.graphics.endFill();

	}
}